package com.wobangkj.common.api.crud;

import com.wobangkj.common.model.crud.Comment;
import com.wobangkj.common.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService CommentService;

    @PostMapping(value = "/create")
    public Object create(@RequestBody Comment data) {
        // 创建时间
        data.setCreatetime(Timestamp.valueOf(LocalDateTime.now()));
        Long a=Long.parseLong(data.getTextId());
        if(data.getCommentTextClass()==0)
        {
            String userId = CommentService.getSharerId(a.toString());
            data.setCommentReplyId(userId);
            return CommentService.create(data);
        }
        else if(data.getCommentTextClass()==1){
            String userId = CommentService.getDynamicPublisherId(a.toString());
            data.setCommentReplyId(userId);
            return CommentService.create(data);
        }
        else {
            String userId = CommentService.getJobPublisherId(a.toString());
            data.setCommentReplyId(userId);
            return CommentService.create(data);
        }
    }

    @PutMapping(value = "/update")
    public Object update(@RequestBody Comment comment) {
        return CommentService.update(comment);
    }

    @DeleteMapping(value = "/delete/{id}")
    public Object delete(@PathVariable(value = "id") Long id) {
        return CommentService.delete(id);
    }

    @GetMapping("/id")
    public Object id(Long id) {
        return CommentService.id(id);
    }


    @GetMapping("/search")
    public Object search(@RequestParam(required = false) Map<String, Object> params, Comment comment) {
        return CommentService.search(params, comment);
    }

    @GetMapping("/getListById")
    public List<Map> getListById(String id,String comment_text_class){
        return CommentService.getListById(id,comment_text_class);
    }

    @GetMapping("/getListByParentId")
    public List<Map> getListByParentId(long id){
        return CommentService.getListByParentId(id);
    }

    @PostMapping(value = "/findMy")
    public Object findMy(String id){
        return CommentService.findMy(id);
    }
}
